home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / C-D / DeveloperStax.cpt / Developer Stack 1.1 / card_9721.txt < prev    next >
Text File  |  1989-02-26  |  6KB  |  194 lines

  1. -- card: 9721 from stack: in.1
  2. -- bmap block id: 0
  3. -- flags: 4000
  4. -- background id: 3837
  5. -- name: NewMenu
  6. ----- HyperTalk script -----
  7. on opencard  -- create the menus
  8.   --  keep the "handles" to the menus in these globals
  9.   global menu1, menu2
  10.   show menubar
  11.   put NewMenu("Beep","Once","Twice","(-","Boing/9") into menu1
  12.   if menu1 is 0 then answer("Unable to make menu 'BEEP'") with "Drat"
  13.   put NewMenu("Visual","Effect 1") into menu2
  14.   if menu2 is 0 then answer("Unable to make menu 'Visual'") with "Drat"
  15. end opencard
  16.  
  17. on closecard  --  delete the menus we've created using
  18.   --the globals saved in openStack
  19.   global menu1, menu2
  20.   put DeleteMenu(menu1) into menu1  --  clearing global for safety
  21.   put DeleteMenu(menu2) into menu2
  22.   hide menubar
  23. end closecard
  24.  
  25.  
  26. on idle  --  call ShowMenu every so often just in case our menus vanished
  27.   global menu1, menu2, lastTick
  28.   if (the ticks-lastTick)>120 then  --  gives better
  29.     -- performance than on every iteration
  30.     put the ticks into lastTick
  31.     ShowMenu(menu1)
  32.     ShowMenu(menu2)
  33.   end if
  34.   pass idle
  35. end idle
  36.  
  37.  
  38. on doMenu which  --  get our menu items from doMenu
  39.   -- before HyperCard does...
  40.   global menu1, menu2  -- for CheckMenu and
  41.   -- EnableMenu below
  42.   if which is "Once" then
  43.     beep 1
  44.     CheckMenu menu1,1,true
  45.   else if which is "Twice" then
  46.     beep 1
  47.     wait 4
  48.     beep 1
  49.     CheckMenu menu1,2,true
  50.   else if which is "Boing" then
  51.     play "Boing"
  52.     CheckMenu menu1,4,true
  53.   else if which is "Effect 1" then
  54.     push card
  55.     visual effect dissolve to black
  56.     pop card
  57.     EnableMenu menu2,1,false
  58.   else pass doMenu  --  Remember to pass on menu commands you don't trap!
  59. end doMenu
  60.  
  61.  
  62.  
  63. -- part 1 (button)
  64. -- low flags: 00
  65. -- high flags: A003
  66. -- rect: left=82 top=302 right=324 bottom=182
  67. -- title width / last selected line: 0
  68. -- icon id / first selected line: 0 / 0
  69. -- text alignment: 1
  70. -- font id: 0
  71. -- text size: 12
  72. -- style flags: 0
  73. -- line height: 16
  74. -- part name: Install
  75. ----- HyperTalk script -----
  76. on mouseUp
  77.   if the optionkey is down then pass mouseup
  78.   put installres(XFCN,NewMenu) into it
  79.   if it is empty then play oops
  80.   else answer it
  81. end mouseUp
  82.  
  83.  
  84.  
  85. -- part contents for background part 5
  86. ----- text -----
  87. NewMenu
  88.  
  89. -- part contents for background part 10
  90. ----- text -----
  91. 3
  92.  
  93. -- part contents for background part 6
  94. ----- text -----
  95.  
  96. NewMenu allows you to add your own menus to a HyperCard stack.  You may have up to eight menus with up to 15 items per menu.  
  97.  
  98. When you change userLevels, or select paint tools, or do anything to cause HyperCard to change the menu bar--your new menu will be erased from the menu bar.  It is NOT gone from memory, just from the menu bar.  To have it replaced automatically do the "on idle" routine shown below.  This will make sure your menu is showing whenever you are in browse mode 
  99. (on idle is not called when you're in button, field, or paint tools mode).
  100.  
  101. All this would generally be done in a stack's script as follows:
  102.  
  103. on openStack  -- create the menus
  104.   --  keep the "handles" to the menus in these globals
  105.   global menu1, menu2  
  106.   put NewMenu("Beep","Once","Twice","(-","Boing/9")   
  107.          into menu1
  108.   if menu1 is 0 then answer("Unable to make menu 'BEEP'")           
  109.         with "Drat"
  110.   put NewMenu("Visual","Effect 1") into menu2
  111.   if menu2 is 0 then answer("Unable to make menu 
  112.         'Visual'") with "Drat"
  113. end openStack
  114.  
  115.  
  116. on closeStack  --  delete the menus we've created using 
  117.                        --the globals saved in openStack
  118.   global menu1, menu2
  119.   put DeleteMenu(menu1) into menu1  --  clearing global
  120.                                                          --  for safety
  121.   put DeleteMenu(menu2) into menu2
  122. end closeStack
  123.  
  124.  
  125. on idle  --  call ShowMenu every so often just in case 
  126.             --  our menus vanished
  127.   global menu1, menu2, lastTick
  128.   if (the ticks-lastTick)>120 then  --  gives better
  129.                            -- performance than on every iteration
  130.     put the ticks into lastTick
  131.     ShowMenu(menu1)
  132.     ShowMenu(menu2)
  133.   end if
  134.   pass idle
  135. end idle
  136.  
  137.  
  138. on doMenu which  --  get our menu items from doMenu 
  139.                            -- before HyperCard does...
  140.   global menu1, menu2  -- for CheckMenu and 
  141.                                    -- EnableMenu below
  142.   if which is "Once" then
  143.     beep 1
  144.     CheckMenu menu1,1,true
  145.   else if which is "Twice" then
  146.     beep 1
  147.     wait 4
  148.     beep 1
  149.     CheckMenu menu1,2,true 
  150.   else if which is "Boing" then
  151.     play "Boing"
  152.     CheckMenu menu1,4,true 
  153.   else if which is "Effect 1" then
  154.     push card
  155.     visual effect dissolve to black
  156.     pop card
  157.     EnableMenu menu2,1,false 
  158.     else pass doMenu  --  Remember to pass on menu 
  159.                                 --  commands you don't trap!
  160. end doMenu
  161.  
  162.  
  163. Notice that if you want the menu to appear for all cards in the stack, you would place the NewMenu function in the stack's script and install it "on openStack" and remove it 
  164. "on closeStack".  If you wanted a menu to appear only for a certain background, the commands would be in that background's script and done "on openBackground" and "on closeBackground".  And the commands to make a menu to appear only on a certain card would be done in that card's script "on openCard"/"on closeCard".
  165.  
  166. •••
  167.  
  168. All the credit, (even the descriptions above) go to the creator of this ingenious XFCN:
  169.  
  170. Nine to Five Software Company
  171. P.O. Box 915
  172. Greenwood, IN  46142
  173. (317) 887-2154
  174. & Michael Long
  175.  
  176. See also CheckMenu*, EnableMenu*, DeleteMenu*, and ChangeMenu*.
  177.  
  178.  
  179. -- part contents for background part 7
  180. ----- text -----
  181. Syntax:
  182.  
  183. put NewMenu("Title","Item1","Item2",...,"Item n") into yourName
  184.  
  185.  
  186. "Title" is the name that will be put into the menubar.
  187.  
  188. "Item1" through "Item n" are the names of the items in the pull down part of the menu.
  189.  
  190. Add an item like "(-" to insert a divider line between menu options.  You may also end items with a slash letter (as is "An item/I") to add command keys.
  191.  
  192.  
  193. The number the NewMenu function returns is a reference number to the menu you just installed.  You MUST have this number to delete or make changes to the menu later on!  
  194.